<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<div id="container">
  <!-- The elements before the form element force the parser to make form 'a'
       the form owner for the textarea and button elements, but at the same
       time prevents the textarea and button elements from being children of
       the form element.
  -->
  <table>
  <colgroup>
  <meter>
  <form id="a">
  <textarea id="b" name="aa"></textarea>
  <button id="c" name="ab"></button>
</div>
<script>
'use strict';

test(() => {
  var form = document.getElementById("a");
  var textarea = document.getElementById("b");
  var input = document.getElementById("c");
  var container = document.getElementById("container");
  document.body.removeChild(container);
  assert_equals(form.aa, textarea);  // validates cache
  textarea.setAttribute("name", "ac"); // should invalidate cache
  input.setAttribute("name", "aa");
  assert_equals(form.aa, input); // should return input and not textarea
  container.children[0].removeChild(container.children[0].children[1]);
  assert_equals(form.ac, undefined);
}, "should invalidate nameditem cache even when removed from document");

</script>
